package com.jshx.sz.gdjt.util;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;

/**
 * 等待框处理类
 * @author xiangchangan
 * @time 2013-08-20
 */
public class ProgressDialogUtil 
{
	/**
	 * 异步加载时等待框
	 */
	private static ProgressDialog progressDialog;

	/**
	 * 显示加载提示框
	 * @param context
	 * @param message
	 * @param cancelable
	 */
	public static void show(Context context, String message, boolean cancelable) {
		if (progressDialog != null)
		{
			ProgressDialogUtil.dismiss();
		}
		progressDialog = new ProgressDialog(context);
		progressDialog.setMessage(message);
		progressDialog.setCancelable(cancelable);
		progressDialog.setIndeterminate(true);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.show();
	}
	
	/**
	 * 显示下载进度框
	 * @param context
	 * @param message
	 * @param cancelable
	 */
	public static ProgressDialog showPrograssDialog(Context context, boolean cancelable) {
		if (progressDialog != null)
		{
			ProgressDialogUtil.dismiss();
		}
		progressDialog = new ProgressDialog(context);
		progressDialog.setMax(100); // 进度最大值
		progressDialog.setTitle("更新进度"); // 设置标题
		progressDialog.setCancelable(cancelable);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		progressDialog.show();
		return progressDialog;
	}

	/**
	 * 设置框加载消失的时候回调
	 * @param listener
	 */
	public static void setDissmissLinserner(OnDismissListener listener)
	{
		if(progressDialog != null)
		{
			progressDialog.setOnDismissListener(listener);
		}
	}
	
	/**
	 * 设置加载框提示消息文字
	 * @param message
	 */
	public static void setMessage(String message) {
		if (progressDialog != null) {
			progressDialog.setMessage(message);
		}
	}

	/**
	 * 加载框消失
	 */
	public static void dismiss() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	/**
	 * 加载框是否正在显示
	 * @return
	 */
	public static boolean isShow() {
		if (progressDialog != null) {
			return progressDialog.isShowing();
		}
		return false;
	}

	/**
	 * 获取当前正在显示的加载框
	 * @return
	 */
	public static ProgressDialog getProgressDialog()
	{
		return progressDialog;
	}
}
